package com.iknow.util;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import com.iknow.Config;
import com.iknow.IKnow;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.security.MessageDigest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SystemUtil
{
  public static char[] HEX_DIGITS;
  private static final String sdIKnowPath;
  private static final String sdIKnowTempPath;
  private static final String sdPath;
  private static final String tag = SystemUtil.class.getName();

  static
  {
    sdPath = getSDPath();
    sdIKnowPath = File.separator + "iknow" + File.separator;
    sdIKnowTempPath = sdIKnowPath + "temp" + File.separator;
    char[] arrayOfChar = new char[16];
    arrayOfChar[0] = 48;
    arrayOfChar[1] = 49;
    arrayOfChar[2] = 50;
    arrayOfChar[3] = 51;
    arrayOfChar[4] = 52;
    arrayOfChar[5] = 53;
    arrayOfChar[6] = 54;
    arrayOfChar[7] = 55;
    arrayOfChar[8] = 56;
    arrayOfChar[9] = 57;
    arrayOfChar[10] = 65;
    arrayOfChar[11] = 66;
    arrayOfChar[12] = 67;
    arrayOfChar[13] = 68;
    arrayOfChar[14] = 69;
    arrayOfChar[15] = 70;
    HEX_DIGITS = arrayOfChar;
  }

  private static void LogI(Object paramObject)
  {
    Loger.i(tag, StringUtil.objToString(paramObject));
  }

  public static void clearCache(Context paramContext)
  {
    LogI("Clear Cache !!!");
    IKFileUtil.deleteAll(paramContext.getCacheDir());
    IKFileUtil.deleteAll(new File(fillSDTempPath("")));
  }

  public static String compareDate(String paramString)
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date localDate1 = new Date(System.currentTimeMillis());
    try
    {
      Date localDate2 = localSimpleDateFormat.parse(paramString);
      long l1 = localDate1.getTime() - localDate2.getTime();
      long l2 = l1 / 86400000L;
      long l3 = l1 / 3600000L - 24L * l2;
      long l4 = l1 / 60000L - 60L * 24L * l2 - 60L * l3;
      (l1 / 1000L - 60L * 60L * 24L * l2 - 60L * 60L * l3 - l4 * 60L);
      if ((l2 >= 1L) && (l2 <= 7L))
      {
        Object[] arrayOfObject2 = new Object[1];
        arrayOfObject2[0] = Long.valueOf(l2);
        localObject = String.format("%d天前", arrayOfObject2);
        break label245:
      }
      if (l2 > 7L)
      {
        localObject = paramString.substring(0, paramString.lastIndexOf(" "));
        break label245:
      }
      if (l2 >= 1L)
        break label242;
      Object[] arrayOfObject1 = new Object[1];
      arrayOfObject1[0] = Long.valueOf(l3);
      String str = String.format("%d小时前", arrayOfObject1);
      localObject = str;
    }
    catch (ParseException localParseException)
    {
      localObject = paramString;
    }
    label242: Object localObject = null;
    label245: return ((String)localObject);
  }

  public static int dip2px(Context paramContext, float paramFloat)
  {
    return (int)(0.5F + paramFloat * paramContext.getResources().getDisplayMetrics().density);
  }

  public static Bitmap drawableToBitmap(Drawable paramDrawable)
  {
    Bitmap.Config localConfig;
    int i = paramDrawable.getIntrinsicWidth();
    int j = paramDrawable.getIntrinsicHeight();
    if (paramDrawable.getOpacity() != -1)
      localConfig = Bitmap.Config.ARGB_8888;
    while (true)
    {
      Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig);
      Canvas localCanvas = new Canvas(localBitmap);
      paramDrawable.setBounds(0, 0, paramDrawable.getIntrinsicWidth(), paramDrawable.getIntrinsicHeight());
      paramDrawable.draw(localCanvas);
      return localBitmap;
      localConfig = Bitmap.Config.RGB_565;
    }
  }

  public static void exit(Activity paramActivity)
  {
    if (paramActivity == null);
    while (true)
    {
      return;
      ((ActivityManager)paramActivity.getSystemService("activity")).restartPackage(paramActivity.getPackageName());
    }
  }

  public static String fillSDPath(String paramString)
  {
    return getSDPath() + sdIKnowPath + paramString;
  }

  public static String fillSDTempPath(String paramString)
  {
    return getSDPath() + sdIKnowTempPath + paramString;
  }

  public static int getDisplayHeight()
  {
    return IKnow.mContext.getResources().getDisplayMetrics().heightPixels;
  }

  public static int getDisplayWidth()
  {
    return IKnow.mContext.getApplicationContext().getResources().getDisplayMetrics().widthPixels;
  }

  public static String getIMEI()
  {
    return ((TelephonyManager)IKnow.mContext.getSystemService("phone")).getDeviceId();
  }

  public static String getIMSI()
  {
    return ((TelephonyManager)IKnow.mContext.getSystemService("phone")).getSubscriberId();
  }

  public static String getMD5(String paramString)
  {
    String str;
    byte[] arrayOfByte = new byte[1024];
    try
    {
      FileInputStream localFileInputStream = new FileInputStream(paramString);
      MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
      int i = localFileInputStream.read(arrayOfByte);
      if (i <= 0)
      {
        localFileInputStream.close();
        str = toHexString(localMessageDigest.digest());
      }
      else
      {
        localMessageDigest.update(arrayOfByte, 0, i);
      }
    }
    catch (Exception localException)
    {
      System.out.println("error");
      str = null;
      return str;
    }
  }

  public static int getResId(Context paramContext, String paramString)
  {
    int i;
    if (StringUtil.isEmpty(paramString))
      i = 0;
    while (true)
    {
      String str2;
      String str3;
      while (true)
      {
        return i;
        String[] arrayOfString = paramString.split("/");
        String str1 = arrayOfString[0];
        str2 = arrayOfString[1];
        str3 = str1.replace("@", "");
        if ((!(StringUtil.isEmpty(str3))) && (!(StringUtil.isEmpty(str2))))
          break;
        i = 0;
      }
      i = paramContext.getResources().getIdentifier(str2, str3, Config.Package.value);
    }
  }

  public static String getSDPath()
  {
    String str;
    if (!(StringUtil.isEmpty(sdPath)))
      str = sdPath;
    while (true)
    {
      while (true)
      {
        return str;
        if (!(Environment.getExternalStorageState().equals("mounted")))
          break;
        str = Environment.getExternalStorageDirectory().toString();
      }
      str = null;
    }
  }

  public static String getSystemConfigFilePath()
  {
    return getSDPath() + File.separator + "iksystem.sys";
  }

  public static int px2dip(Context paramContext, float paramFloat)
  {
    return (int)(0.5F + paramFloat / paramContext.getResources().getDisplayMetrics().density);
  }

  public static String toHexString(byte[] paramArrayOfByte)
  {
    StringBuilder localStringBuilder = new StringBuilder(2 * paramArrayOfByte.length);
    int i = 0;
    while (true)
    {
      if (i >= paramArrayOfByte.length)
        return localStringBuilder.toString();
      localStringBuilder.append(HEX_DIGITS[((0xF0 & paramArrayOfByte[i]) >>> 4)]);
      localStringBuilder.append(HEX_DIGITS[(0xF & paramArrayOfByte[i])]);
      ++i;
    }
  }
}